import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import Layout from '@/layout'
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        name: 'Dashboard',
        component: () => import('@/views/dashboard/index'),
        meta: { title: '首页', icon: 'dashboard' }
      }
    ]
  },

  { path: '*', redirect: '/404', hidden: true },
  // 楼层管理
  {
    path: '/floorPt',
    component: () => import('@/views/floorPt/index'),
    hidden: true
  },
  // 设备生命周期管理
  {
    path: '/lifecycle',
    component: () => import('@/views/lifecycle/index'),
    hidden: true
  }
]

const createRouter = () =>
  new Router({
    // 路由模式 默认是有#号
    mode: 'history',
    // 配置router的参数文件
    // base 参数 所有的请求都会在url之后加上这个参数
    // http://localhost:8080/base参数才能访问
    scrollBehavior: () => ({ y: 0 }),
    routes: [...constantRoutes, ...asyncRoutes]
  })
// 导入动态路由表 在父级目录写动态路由表

const asyncRoutes = []

const router = createRouter()

export function resetRouter () {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
